App.MainApp.module('toolbarDialogModule', function(toolbarDialogModule){
	var _toolbardialog = null;
	var _width = 400;
	var _height = 50;
	var _container = '#main-layout';
	// View for Layout
   var MainView = Marionette.ItemView.extend({
   });
	this.startWithParent = false;
	// Controller for Layout
	Controller = Marionette.Controller.extend({
		initialize: function(options){
			if (App.debug) console.log('App.toolbarDialogModule Controller initialized');
			this.region = options.region
		},
		show: function(options) {
			if (App.debug) console.log('App.toolbarDialogModule Controller show invoked');
			var main_view = new MainView({
				id: options.id,
				template: options.template
			});
			this.region.show(main_view);
		},
		render: function(options) {
			if (App.debug) console.log('App.toolbarDialogModule Controller render invoked');
         _toolbardialog =  $('#' + options.id).wijdialog({
				title: 'Toolbar',
            autoOpen: true,
				dialogClass: 'toolbar-dialog',
				height: _height,
				width: _width,
				resizable: false,
            captionButtons: {
               refresh: { visible: false}
            },
				position: {
					my: 'center bottom',
					at: 'center bottom-15',
					of: $(_container)
				}
         });
			_toolbardialog = $('#' + options.id).wijdialog('widget');
		},
		position: function() {
			if (App.debug) console.log('App.toolbarDialogModule Controller position invoked');
			_toolbardialog.position({
				my: 'center bottom',
				at: 'center bottom-15',
				of: $(_container)
			});
		}
	});
	
	toolbarDialogModule.addInitializer(function (options) {
		var defaults = {
			id: 'toolbarDialog',
			template: '#toolbar-dialog-layout-template',
			region: App.MainApp.toolbarDialogRegion
		};
		options = _.extend(defaults, options);
		if (App.debug) console.log('App.toolbarDialogModule addInitializer');
		toolbarDialogModule.Controller = new Controller({
			region: options.region
		});
		toolbarDialogModule.Controller.show(options);
		toolbarDialogModule.Controller.render(options);
   });

});

App.MainApp.toolbarDialogModule.on("before:start", function(){
	if (App.debug) console.log('App.toolbarDialogModule before:start');
});

App.MainApp.toolbarDialogModule.on("start", function(){
	if (App.debug) console.log('App.toolbarDialogModule start');
	
});

